<?php
require_once('internal/Engine.base.php');
// Sample2 engine
class Sample2 extends Engine {
	protected function content() {
		global $mae;
		$file = fopen('engines/sample2/text.txt', 'r');
		while ($row = fgets($file)) echo $row.'<br />';
		fclose($file);
		echo '<br />This is a demo of the mae. engines architecture.';
	}
	function configure() {
		if ($_POST['text']) $this->save();
		global $mae;
		$file = fopen('engines/sample2/text.txt', 'r');
		$row = array();
		while (!feof($file)) array_push($row, fgets($file));
		fclose($file);
		?>
		<script type="text/javascript">
		 function doSave() {
		  $$('form')[0].submit();
		 }
		</script>
		<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
			<textarea name="text" rows="20" cols="70"><?php for ($i=0; $i<count($row); $i++) echo $row[$i]; ?></textarea>
		</form>
		<?php
	}
	private function save() {
		global $mae;
		$file = fopen('engines/sample2/text.txt', 'w');
		fwrite($file, $_POST['text']);
		fclose($file);
		print '<div id="message">Saved!</div>';
	}
}
?>
